using Eno.Application.Dto;
using Eno.Application.Services;
using Eno.Infrastructure.Tools;
using Microsoft.AspNetCore.Mvc;

namespace Eno.Api.Controllers;

[ApiController]
[Route("manager/todo")]
public class RoleUserController : ControllerBase
{
    private readonly AppointRemoveService _userRoleService;

    public RoleUserController(AppointRemoveService appointRemoveService)
    {
        _userRoleService = appointRemoveService;
    }

    [HttpPost("addition")]
    public async Task<IActionResult> AdditionUserToRole(UserRoleDto userRoleDto)
    {
        var result = await _userRoleService.AppointUserToRole(userRoleDto.Rid, userRoleDto.Uid);
        if (result == 0) return Ok(Tips<string>.Fail(""));
        return Ok(Tips<int>.Success(result, "指派角色成功"));
    }

    [HttpDelete("delete")]
    public async Task<IActionResult> DeleteUserToRole(UserRoleDto userRoleDto)
    {
        var result = await _userRoleService.RemoveUserToRole(userRoleDto.Rid, userRoleDto.Uid);
        if (result == 0) return Ok(Tips<string>.Fail(""));
        return Ok(Tips<int>.Success(result, "移除角色成功"));
    }

}